space_object:get()
-
object
space_object -
space_object:get(key) Search for a tuple in the given space.
Parameters: - space_object (space_object) – an object reference
- key (scalar/table) – value to be matched against the index key, which may be multi-part.
Return: the tuple whose index key matches
key, ornil.Rtype: tuple
Possible errors:
space_objectdoes not exist.Complexity factors: Index size, Index type, Number of indexes accessed, WAL settings.
The
box.space...selectfunction returns a set of tuples as a Lua table; thebox.space...getfunction returns at most a single tuple. And it is possible to get the first tuple in a space by appending[1]. Thereforebox.space.tester:get{1}has the same effect asbox.space.tester:select{1}[1], if exactly one tuple is found.Example:
box.space.tester:get{1}
Using field names instead of field numbers:
get()can use field names described by the optional space_object:format() clause. This is similar to a standard Lua feature, where a component can be referenced by its name instead of its number. For example, we can format thetesterspace with a field namedxand use the namexin the index definition:box.space.tester:format({{name='x',type='scalar'}}) box.space.tester:create_index('I',{parts={'x'}})
Then, if
getorselectretrieve a single tuple, we can reference the field ‘x’ in the tuple by its name:box.space.tester:get{1}['x'] box.space.tester:select{1}[1]['x']
-